#include <iostream>
#include <signal.h>

using namespace std;

void Print(sigset_t &penging)
{
    for (int sig = 31; sig > 0; sig--)
    {
        if (sigismember(&penging, 2))
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout << endl;
}

void handler(int signo)
{
    cout << "signo:" << signo << endl;
    sleep(1);
    while (true)
    {
        sigset_t pending;
        sigpending(&pending);
        Print(pending);
        sleep(1);
    }
}
// volatile 保持内存可见性

int main()
{
    cout << getpid() << endl;
    struct sigaction act, oact;
    act.sa_handler = handler;

    sigaction(2, &act, &oact);
    while (true)
    {
        sigset_t pending;
        sigpending(& pending);
        Print(pending);
        sleep(1);
    }
    return 0;
}